using SQLServices.RunnableItems;

namespace SQLRunnerLib.RunnableItems
{
    /// <summary>
    /// Summary description for PathItem.
    /// </summary>
    public class PathItem : IPathItemOld
    {

        #region Private Instances

        private string _name;
        private IPathItemOld _prevNode;
        private IPathItemOld _nextNode;

        #endregion
        #region Constructor

        public PathItem(string name, IPathItemOld prevNode)
        {
            _name = name;
            PrevNode = prevNode;
        }

        #endregion
        #region Public Methods

        public string FullPath()
        {
            if (PrevNode == null)
                return _name;
            else
                return _prevNode.FullPath() + "\\" + _name;
        }

        public IPathItemOld FirstNode()
        {
            if(_prevNode == null) 
                return this;
            else
                return _prevNode.FirstNode();
        }

        #endregion
        #region Properties

        public string Name
        {
            get{ return _name; }
        }

        public IPathItemOld PrevNode
        {
            get { return _prevNode; }
            set
            {
                _prevNode = value;
                if ( value != null && value.NextNode != this)
                { value.NextNode = this; }
            }
        }

        public IPathItemOld NextNode
        {
            get { return _nextNode; }
            set
            {
                _nextNode = value;
                if ( value != null && value.PrevNode != this )
                { value.PrevNode = this; }
            }
        }


        #endregion

    }
}